/* 
 * File:   MaintenanceMode.cpp
 * Author: taylor
 * 
 * Created on November 7, 2012, 2:33 PM
 */

#include "MaintenanceMode.h"

/**
 * Initialize/enable maintence mode
 */
void MaintenanceMode::enableMode() {
    int opt;
    enabled = true;
    
    outputOptions();
    
        
    while(/*cin >> opt  &&*/ enabled){
        cin >> opt;
        getChosenOption(opt);
    }
}

/**
 * Output the options menu for maintenence mode
 */
void MaintenanceMode::outputOptions() {
    cout << "What would you like to do?" << endl;
        cout << "\t1. Add a document to the corpus." << endl;
        cout << "\t2. Clear the search index." << endl << endl;
        cout << "\t3. Switch Modes." << endl;
}

/**
 * Parse the chosen option and carry out the operation
 * @param opt number representing the option chosen
 */
void MaintenanceMode::getChosenOption(int opt) {
    string str;
    
    switch(opt) {
        case 1: //Add doc
        {    
            cout << "What is the name of the file? (Include directory path)" << endl;
            cin >> str;
            addDocument(str);
            
            outputOptions();
            break;
        }
        case 2: //Clear index
        {
            
            outputOptions();
            break;
        }
        case 3: //Switch modes
        {
            enabled = false;
            return;
            break;
        }
        case 4: //Quit
        {
            exit(EXIT_SUCCESS);
        }   
    }
}

/**
 * Parse all documents from a file into the tree structure
 * @param file
 */
void MaintenanceMode::addDocument(string file) {
    //DocumentManager dm;
    dm->addDocumentsFromFile(file);
}

/**
 * Clear the whole index
 */
void MaintenanceMode::clearIndex() {
    
}

/**
 * Constructor for document manager
 * @param dm_i ptr to the DocumentManager object to use
 */
MaintenanceMode::MaintenanceMode(DocumentManager* dm_i){
    dm_i = new DocumentManager('b');
    dm = dm_i;
}
